package cn.itsource.system.controller;

import cn.itsource.basic.util.PageBean;
import cn.itsource.org.domain.Department;
import cn.itsource.system.service.IMenuService;
import cn.itsource.system.domain.Menu;
import cn.itsource.system.query.MenuQuery;
import cn.itsource.basic.util.AjaxResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    public IMenuService menuService;


    /**
     * 保存和修改公用的
     * @param menu  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Menu menu){
        if( menu.getId()!=null)
            menuService.update(menu);
        else
            menuService.add(menu);
        return AjaxResult.me();
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        menuService.delete(id);
        return AjaxResult.me();
    }
	
    //获取用户
    @GetMapping("/{id}")
    public Menu get(@PathVariable("id")Long id)
    {
        return menuService.queryById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    public List<Menu> list(){
        return menuService.queryAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping("/list")
    public PageBean<Menu> json(@RequestBody MenuQuery query)
    {
        return menuService.pageList(query);
    }


    @GetMapping("/tree")  //  http://localhost:8080/dept/tree + Get
    public List<Menu> tree(){
        return menuService.tree();
    }
}
